<template>
	<view class="cardlist">
		<view class="btn" @click="toaddcard(1)" v-if="type == 2">更改银行卡</view>
		<view class="btn" @click="toaddcard(2)" v-if="type == 1">添加银行卡</view>
		<view class="wu" v-if="type == 1">暂无银行卡</view>
		<view class="cardbox" v-if="type == 2">
			
			<view class="cardcon"  v-for="(item,index) in cardlist" :key="index">
				<view><text>开户名</text>{{item['kh_xingming']}}</view>
				<view><text>开户行</text>{{item['bank_name']}}</view>
				<view><text>开户地址</text>{{item['bank_khh']}}</view>
				<view><text>银行卡号</text>{{item['bank_card']}}</view>
			</view>

		</view>

	</view>
</template>

<script>
	var _this;
	import { mapState } from 'vuex';
	export default {
		data() {
			return {
              type:0
			}
		},

		methods: {

			toaddcard(item) {
				var temp = this.cardlist[0];
				if(item==2){
					uni.navigateTo({
						url: '../xgcard/index?type=' + item 
					})
				}
				else{
					uni.navigateTo({
						url: '../xgcard/index?type=' + item + "&username=" + temp['kh_xingming'] + "&bank=" + temp['bank_name'] + "&bankzhi=" + temp['bank_khh']+ "&bankbh=" + temp['bank_card'] + "&card_id=" + temp['card_id'] 
					})
				}	
			},
			

		},
		onShow() {
			_this = this;
			var data = {
				token: uni.getStorageSync('token')
			}
			this.$store
				.dispatch('cardlist', data)
				.then(res => {
					if(res.data.data){
						_this.type = 2;
						 console.log(this.type);
					}
					else{
						_this.type = 1;
						 console.log(this.type);
					}
			  })
			  console.log(_this.type);
		},
		onLoad() {
			// var data = {
			// 	token: uni.getStorageSync('token')
			// }
			// this.$store
			// 	.dispatch('cardlist', data)
			// 	.then(res => {
			// 		if(res.data.data){
			// 			this.type = 2;
			// 		}
			// 		else{
			// 			this.type = 1;
			// 		}
		 //      })
			  
		},
		computed: mapState({
			 cardlist: 'cardlist'
		})
	}
</script>
<style lang="scss" scoped src="./index.scss"></style>
